package com.jsu.forum.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;
import org.example.model.forum.pojo.Passage;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.stream.Collectors;

@Mapper
public interface PassageMapper extends BaseMapper<Passage> {
    List<Passage> findLatestPassageByPage(@Param("page") int page, @Param("pageSize") int pageSize);

    @Update("UPDATE passage SET like_count = like_count + 1 WHERE pk_id = #{passageId}")
    int addLike(Integer passageId);

    @Update("UPDATE passage SET comment_count = comment_count + 1 WHERE pk_id = #{passageId}")
    int addComment(Integer passageId);

    @Update("UPDATE passage SET like_count = like_count - 1 WHERE pk_id = #{passageId}")
    int reduceLike(Integer passageId);
    @Update("UPDATE passage SET comment_count = comment_count - 1 WHERE pk_id = #{passageId}")
    int reduceComment(Integer passageId);

    @Update("UPDATE passage SET count = count + 1 WHERE pk_id = #{passageId}")
    int addCount(Integer passageId);
}
